package com.guigu.userservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.common.utils.R;
import com.guigu.userservice.entity.SellerQualification;
import com.guigu.userservice.entity.User;
import com.guigu.userservice.mapper.SellerQualificationMapper;
import com.guigu.userservice.service.SellerQualificationService;
import com.guigu.userservice.vo.SellerQualificationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 卖家资质表（存储卖家实名认证材料及审核结果） 服务实现类
 * </p>
 *
 * @author zcy
 * @since 2025-09-27
 */
@Service
public class SellerQualificationServiceImpl extends ServiceImpl<SellerQualificationMapper, SellerQualification> implements SellerQualificationService {
    @Autowired
    private SellerQualificationMapper sellerQualificationMapper;

    @Override
    public R querySellerQualificationByVo(Integer pageNum, Integer pageSize, SellerQualificationVo vo) {
        PageHelper.startPage(pageNum, pageSize);
        QueryWrapper<SellerQualification> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(vo.getSearchId() != null, "user_id", vo.getSearchId());
        queryWrapper.eq(vo.getSearchType() != null, "seller_type", vo.getSearchType());
        queryWrapper.eq(vo.getAuditStatus() != null, "audit_status", vo.getSearchType());
        queryWrapper.ge(vo.getSearchMinTime() != null && !vo.getSearchMinTime().toString().isEmpty(), "apply_time", vo.getSearchMinTime());
        queryWrapper.le(vo.getSearchMaxTime() != null && !vo.getSearchMaxTime().toString().isEmpty(), "apply_time", vo.getSearchMaxTime());

        List<SellerQualification> SellerQualifications = sellerQualificationMapper.selectList(queryWrapper);
        PageInfo<SellerQualification> pageInfo = new PageInfo<>(SellerQualifications);
        return R.ok().data("pageInfo", pageInfo);
    }

    @Override
    public R querySellerQualificationDetail(Integer sellerQualificationId) {
        SellerQualification sellerQualification = sellerQualificationMapper.selectById(sellerQualificationId);
        return R.ok().data("sellerQualification", sellerQualification);
    }
}
